package com.yiduan.apollocrm.views.mediators
{
	import com.yiduan.apollocrm.models.Opportunity;
	import com.yiduan.apollocrm.views.NewOrEditOpportunityView;
	import com.yiduan.apollocrm.views.OpportunitiesView;
	
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	import mx.collections.ArrayCollection;
	import mx.resources.ResourceManager;
	
	import org.robotlegs.mvcs.Mediator;
	
	public class OpportunitiesMediator extends Mediator
	{
		[Inject]
		public var opportunitiesView:OpportunitiesView;		
		
		public function OpportunitiesMediator() {
			super();
		}
		
		override public function onRegister():void {
			getOpportunityList();
			opportunitiesView.newOpportunityBtn.addEventListener(MouseEvent.CLICK, newOpportunityHandler);
		}
		
		private function newOpportunityHandler(e:Event):void {
			opportunitiesView.navigator.pushView(NewOrEditOpportunityView);
		}
		
		private function getOpportunityList():void {
			var opportunityCollection:ArrayCollection = new ArrayCollection();
			var opportunity1:Opportunity = new Opportunity();
			opportunity1.name = "业务机会1";
			opportunityCollection.addItem(opportunity1);
			var opportunity2:Opportunity = new Opportunity();
			opportunity2.name = "业务机会2";
			opportunityCollection.addItem(opportunity2);
			var opportunity3:Opportunity = new Opportunity();
			opportunity3.name = "业务机会3";
			opportunityCollection.addItem(opportunity3);
			var opportunity4:Opportunity = new Opportunity();
			opportunity4.name = "业务机会4";
			opportunityCollection.addItem(opportunity4);
			var opportunity5:Opportunity = new Opportunity();
			opportunity5.name = "业务机会5";
			opportunityCollection.addItem(opportunity5);
			opportunitiesView.opportunityList.dataProvider = opportunityCollection;
		}

	}
}